/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.table.editor;

import com.rw.table.TableInfo;
import com.rw.table.formatter.ICellFormatter;
import java.awt.Component;
import javax.swing.JComboBox;

/**
 *
 * @author Rene Tapia
 */
public class ComboCellEditor extends ACellEditor {

    private JComboBox combo;

    public ComboCellEditor(Object[] values) {
        this.combo = new JComboBox(values);
        this.combo.setOpaque(true);
    }

    @Override
    public Component getComponent(TableInfo info) {
        Object value = info.getValue();
        if (value != null) {
            combo.setSelectedItem(value);
        } else {
            combo.setSelectedIndex(0);
        }
        return combo;
    }

    @Override
    public Object getCellEditorValue(ICellFormatter formatter) {
        return this.combo.getSelectedItem();
    }
}
